<?php
declare(strict_types=1);

namespace Service\HelperService;

class StringService
{
    public static function hide_mobile(string $mobile = ''):string{
        return str_replace(substr($mobile, 3, 4), '****', $mobile);
    }
    
    public static function hide_idcard(string $idcard = ''):string{
        return str_replace(substr($idcard, 6, 8), '********', $idcard);
    }
    
    /**
     * 将字符串中间部分隐藏为***
     *
     * @param  string $str
     * @return string
     */
    public static function make_star($str = '')
    {
        if($str){
            $strlength=mb_strlen($str,'utf-8');
            $length=$strlength>2?$strlength-2:1;  
            $str=str_replace(mb_substr($str, 1, $length,'utf-8'), str_repeat('*', $length), $str);
        }
        return $str;
    }
    
    /**
     * 根据扫码判断码是微信的支付授权码还是支付宝授权码
     * @param type $acthcode
     * @return string
     */
    public static function checkPayAuthCode($acthcode){
        $payway='';
        $scancodeflag= substr($acthcode, 0,2);
        if($scancodeflag>=20){
            $payway='ALIPAY';
        }else{
            $payway='WECHATPAY';
        }
        return $payway;
    }
}
